package jnpf.zc.service.impl;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.base.ActionResult;
import jnpf.base.UserInfo;
import jnpf.base.entity.DictionaryDataEntity;
import jnpf.base.mapper.DictionaryDataMapper;
import jnpf.exception.DataException;
import jnpf.model.visiual.superQuery.ConditionJsonModel;
import jnpf.model.visiual.superQuery.SuperQueryConditionModel;
import jnpf.model.visiual.superQuery.SuperQueryJsonModel;
import jnpf.permission.model.authorize.AuthorizeConditionModel;
import jnpf.permission.service.AuthorizeService;
import jnpf.report.vo.YsRaportVO;
import jnpf.report.vo.ZcglZcdjInfoEntityRaportVO;
import jnpf.util.*;
import jnpf.zc.entity.*;
import jnpf.zc.mapper.*;
import jnpf.zc.model.zcglzcdjinfo.*;
import jnpf.zc.service.ZcglZcdjAreaService;
import jnpf.zc.service.ZcglZcdjInfoService;
import jnpf.zc.service.ZcglZcdjPhotoService;
import jnpf.zc.service.ZcglZcdjWarrantService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 资产登记
 * 版本： V3.2.0
 * 版权： 智果云科技（https://www.jnpfsoft.com）
 * 作者： JNPF开发平台组
 * 日期： 2024-12-19
 */
@Service
public class ZcglZcdjInfoServiceImpl extends ServiceImpl<ZcglZcdjInfoMapper, ZcglZcdjInfoEntity> implements ZcglZcdjInfoService {

    @Autowired
    private GeneraterSwapUtil generaterSwapUtil;

    @Autowired
    private UserProvider userProvider;

    @Autowired
    private AuthorizeService authorizeService;

    @Autowired
    private ZcglZcdjAreaService zcglZcdjAreaService;
    @Autowired
    private ZcglZcdjWarrantService zcglZcdjWarrantService;
    @Autowired
    private ZcglZcdjPhotoService zcglZcdjPhotoService;
    @Autowired
    private ZcglZcdjInfoChangeMapper zcglZcdjInfoChangeMapper;
    @Autowired
    private ZcglZcdjWarrantMapper zcglZcdjWarrantMapper;
    @Autowired
    private ZcglZcdjAreaMapper zcglZcdjAreaMapper;
    @Autowired
    private ZcglZcdjPhotoMapper zcglZcdjPhotoMapper;
    @Autowired
    private DictionaryDataMapper dictionaryDataMapper;


    @Override
    public List<ZcglZcdjInfoEntityRaportVO> getReport(ZcglZcdjInfoPagination zcglZcdjInfoPagination) {
        return baseMapper.getReport(zcglZcdjInfoPagination);
    }

    @Override
    public Integer getReportCount(ZcglZcdjInfoPagination zcglZcdjInfoPagination) {
        return baseMapper.getReportCount(zcglZcdjInfoPagination);
    }

    @Override
    public List<YsRaportVO> getReportYs(ZcglZcdjInfoPagination zcglZcdjInfoPagination) {
        return baseMapper.getReportYs(zcglZcdjInfoPagination);
    }

    @Override
    public Integer getReportCountYs(ZcglZcdjInfoPagination zcglZcdjInfoPagination) {
        return baseMapper.getReportCountYs(zcglZcdjInfoPagination);
    }

    @Override
    public List<ZcglZcdjInfoEntity> getList(ZcglZcdjInfoPagination zcglZcdjInfoPagination) {
        return getTypeList(zcglZcdjInfoPagination, zcglZcdjInfoPagination.getDataType());
    }

    @Override
    public List<ZcglZcdjInfoEntity> getTypeList(ZcglZcdjInfoPagination zcglZcdjInfoPagination, String dataType) {
        String userId = userProvider.get().getUserId();
        List<String> AllIdList = new ArrayList();
        List<List<String>> intersectionList = new ArrayList<>();
        int total = 0;
        int zcglZcdjInfoNum = 0;
        QueryWrapper<ZcglZcdjInfoEntity> zcglZcdjInfoQueryWrapper = new QueryWrapper<>();
        int zcglZcdjWarrantNum = 0;
        QueryWrapper<ZcglZcdjWarrantEntity> zcglZcdjWarrantQueryWrapper = new QueryWrapper<>();
        int zcglZcdjAreaNum = 0;
        QueryWrapper<ZcglZcdjAreaEntity> zcglZcdjAreaQueryWrapper = new QueryWrapper<>();
        int zcglZcdjPhotoNum = 0;
        QueryWrapper<ZcglZcdjPhotoEntity> zcglZcdjPhotoQueryWrapper = new QueryWrapper<>();
        long zcglZcdjWarrantcount = zcglZcdjWarrantService.count();
        long zcglZcdjAreacount = zcglZcdjAreaService.count();
        long zcglZcdjPhotocount = zcglZcdjPhotoService.count();
        List<String> allSuperIDlist = new ArrayList<>();
        String superOp = "";
        if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getSuperQueryJson())) {
            SuperQueryJsonModel superQueryJsonModel = JsonUtil.getJsonToBean(zcglZcdjInfoPagination.getSuperQueryJson(), SuperQueryJsonModel.class);
            String matchLogic = superQueryJsonModel.getMatchLogic();
            List<ConditionJsonModel> superQueryList = JsonUtil.getJsonToList(superQueryJsonModel.getConditionJson(), ConditionJsonModel.class);
            for (ConditionJsonModel conditionjson : superQueryList) {
                Map<String, Object> map = JsonUtil.stringToMap(conditionjson.getAttr());
                Map<String, Object> configMap = JsonUtil.stringToMap(map.get("__config__").toString());
                String tableName = configMap.get("relationTable") != null ? String.valueOf(configMap.get("relationTable")) : String.valueOf(configMap.get("tableName"));
                if (map.get("multiple") != null) {
                    if (Boolean.valueOf(String.valueOf(map.get("multiple"))) && ObjectUtil.isNull(conditionjson.getFieldValue())) {
                        conditionjson.setFieldValue("[]");
                    }
                }
                conditionjson.setTableName(tableName);
            }
            List<String> allSuperList = new ArrayList<>();
            List<List<String>> intersectionSuperList = new ArrayList<>();
            int zcglZcdjInfoNum1 = 0;
            QueryWrapper<ZcglZcdjInfoEntity> zcglZcdjInfoSuperWrapper = new QueryWrapper<>();
            zcglZcdjInfoNum1 = generaterSwapUtil.getCondition(new SuperQueryConditionModel(zcglZcdjInfoSuperWrapper, superQueryList, matchLogic, "zcglZcdjInfo")
                    , new ZcglZcdjInfoEntity(), zcglZcdjInfoNum1);
            if (zcglZcdjInfoNum1 > 0) {
                List<String> zcglZcdjInfoList = this.list(zcglZcdjInfoSuperWrapper).stream().map(ZcglZcdjInfoEntity::getId).collect(Collectors.toList());
                allSuperList.addAll(zcglZcdjInfoList);
                intersectionSuperList.add(zcglZcdjInfoList);
            }
            int zcglZcdjWarrantNum1 = 0;
            QueryWrapper<ZcglZcdjWarrantEntity> zcglZcdjWarrantSuperWrapper = new QueryWrapper<>();
            zcglZcdjWarrantNum1 = generaterSwapUtil.getCondition(new SuperQueryConditionModel(zcglZcdjWarrantSuperWrapper, superQueryList, matchLogic, "zcglZcdjWarrant")
                    , new ZcglZcdjWarrantEntity(), zcglZcdjWarrantNum1);
            if (zcglZcdjWarrantNum1 > 0 && zcglZcdjWarrantcount > 0) {
                List<String> zcglZcdjWarrantList = zcglZcdjWarrantService.list(zcglZcdjWarrantSuperWrapper).stream().map(ZcglZcdjWarrantEntity::getParentId).collect(Collectors.toList());
                allSuperList.addAll(zcglZcdjWarrantList);
                intersectionSuperList.add(zcglZcdjWarrantList);
            }
            int zcglZcdjAreaNum1 = 0;
            QueryWrapper<ZcglZcdjAreaEntity> zcglZcdjAreaSuperWrapper = new QueryWrapper<>();
            zcglZcdjAreaNum1 = generaterSwapUtil.getCondition(new SuperQueryConditionModel(zcglZcdjAreaSuperWrapper, superQueryList, matchLogic, "zcglZcdjArea")
                    , new ZcglZcdjAreaEntity(), zcglZcdjAreaNum1);
            if (zcglZcdjAreaNum1 > 0 && zcglZcdjAreacount > 0) {
                List<String> zcglZcdjAreaList = zcglZcdjAreaService.list(zcglZcdjAreaSuperWrapper).stream().map(ZcglZcdjAreaEntity::getParentId).collect(Collectors.toList());
                allSuperList.addAll(zcglZcdjAreaList);
                intersectionSuperList.add(zcglZcdjAreaList);
            }
            int zcglZcdjPhotoNum1 = 0;
            QueryWrapper<ZcglZcdjPhotoEntity> zcglZcdjPhotoSuperWrapper = new QueryWrapper<>();
            zcglZcdjPhotoNum1 = generaterSwapUtil.getCondition(new SuperQueryConditionModel(zcglZcdjPhotoSuperWrapper, superQueryList, matchLogic, "zcglZcdjPhoto")
                    , new ZcglZcdjPhotoEntity(), zcglZcdjPhotoNum1);
            if (zcglZcdjPhotoNum1 > 0 && zcglZcdjPhotocount > 0) {
                List<String> zcglZcdjPhotoList = zcglZcdjPhotoService.list(zcglZcdjPhotoSuperWrapper).stream().map(ZcglZcdjPhotoEntity::getParentId).collect(Collectors.toList());
                allSuperList.addAll(zcglZcdjPhotoList);
                intersectionSuperList.add(zcglZcdjPhotoList);
            }
            superOp = matchLogic;
            //and or
            if (matchLogic.equalsIgnoreCase("and")) {
                allSuperIDlist = generaterSwapUtil.getIntersection(intersectionSuperList);
            } else {
                allSuperIDlist = allSuperList;
            }
        }
        boolean pcPermission = false;
        boolean appPermission = false;
        boolean isPc = ServletUtil.getHeader("jnpf-origin").equals("pc");
        if (isPc && pcPermission) {
            if (!userProvider.get().getIsAdministrator()) {
                Object zcglZcdjInfoObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjInfoQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcgl_zcdj_info"));
                if (ObjectUtil.isEmpty(zcglZcdjInfoObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjInfoQueryWrapper = (QueryWrapper<ZcglZcdjInfoEntity>) zcglZcdjInfoObj;
                    zcglZcdjInfoNum++;
                }
                Object zcglZcdjWarrantObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjWarrantQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcgl_zcdj_warrant"));
                if (ObjectUtil.isEmpty(zcglZcdjWarrantObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjWarrantQueryWrapper = (QueryWrapper<ZcglZcdjWarrantEntity>) zcglZcdjWarrantObj;
                    zcglZcdjWarrantNum++;
                }
                Object zcglZcdjAreaObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjAreaQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcgl_zcdj_area"));
                if (ObjectUtil.isEmpty(zcglZcdjAreaObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjAreaQueryWrapper = (QueryWrapper<ZcglZcdjAreaEntity>) zcglZcdjAreaObj;
                    zcglZcdjAreaNum++;
                }
                Object zcglZcdjPhotoObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjPhotoQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcgl_zcdj_photo"));
                if (ObjectUtil.isEmpty(zcglZcdjPhotoObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjPhotoQueryWrapper = (QueryWrapper<ZcglZcdjPhotoEntity>) zcglZcdjPhotoObj;
                    zcglZcdjPhotoNum++;
                }
            }
        }
        if (!isPc && appPermission) {
            if (!userProvider.get().getIsAdministrator()) {
                Object zcglZcdjInfoObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjInfoQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcglZcdjInfo"));
                if (ObjectUtil.isEmpty(zcglZcdjInfoObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjInfoQueryWrapper = (QueryWrapper<ZcglZcdjInfoEntity>) zcglZcdjInfoObj;
                    zcglZcdjInfoNum++;
                }
                Object zcglZcdjWarrantObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjWarrantQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcglZcdjWarrant"));
                if (ObjectUtil.isEmpty(zcglZcdjWarrantObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjWarrantQueryWrapper = (QueryWrapper<ZcglZcdjWarrantEntity>) zcglZcdjWarrantObj;
                    zcglZcdjWarrantNum++;
                }
                Object zcglZcdjAreaObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjAreaQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcglZcdjArea"));
                if (ObjectUtil.isEmpty(zcglZcdjAreaObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjAreaQueryWrapper = (QueryWrapper<ZcglZcdjAreaEntity>) zcglZcdjAreaObj;
                    zcglZcdjAreaNum++;
                }
                Object zcglZcdjPhotoObj = authorizeService.getCondition(new AuthorizeConditionModel(zcglZcdjPhotoQueryWrapper, zcglZcdjInfoPagination.getMenuId(), "zcglZcdjPhoto"));
                if (ObjectUtil.isEmpty(zcglZcdjPhotoObj)) {
                    return new ArrayList<>();
                } else {
                    zcglZcdjPhotoQueryWrapper = (QueryWrapper<ZcglZcdjPhotoEntity>) zcglZcdjPhotoObj;
                    zcglZcdjPhotoNum++;
                }
            }
        }
        if (isPc) {
            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getZcNumber())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().like(ZcglZcdjInfoEntity::getZcNumber, zcglZcdjInfoPagination.getZcNumber());
            }

            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getZcName())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().like(ZcglZcdjInfoEntity::getZcName, zcglZcdjInfoPagination.getZcName());
            }

            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getLongitude())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().like(ZcglZcdjInfoEntity::getLongitude, zcglZcdjInfoPagination.getLongitude());
            }

            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getLatitude())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().like(ZcglZcdjInfoEntity::getLatitude, zcglZcdjInfoPagination.getLatitude());
            }

            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getZcNature())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().eq(ZcglZcdjInfoEntity::getZcNature, zcglZcdjInfoPagination.getZcNature());
            }

            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getZcPurpose())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().eq(ZcglZcdjInfoEntity::getZcPurpose, zcglZcdjInfoPagination.getZcPurpose());
            }

            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getZcSource())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().eq(ZcglZcdjInfoEntity::getZcSource, zcglZcdjInfoPagination.getZcSource());
            }

            if (ObjectUtil.isNotEmpty(zcglZcdjInfoPagination.getAffiliatedUnit())) {
                zcglZcdjInfoNum++;
                zcglZcdjInfoQueryWrapper.lambda().eq(ZcglZcdjInfoEntity::getAffiliatedUnit, zcglZcdjInfoPagination.getAffiliatedUnit());
            }

        }


        if (zcglZcdjWarrantNum > 0) {
            List<String> zcglZcdjWarrantIdList = zcglZcdjWarrantService.list(zcglZcdjWarrantQueryWrapper).stream().filter(t -> StringUtil.isNotEmpty(t.getParentId())).map(t -> t.getParentId()).collect(Collectors.toList());
            long count = zcglZcdjWarrantService.count();
            if (count > 0) {
                intersectionList.add(zcglZcdjWarrantIdList);
            }
            AllIdList.addAll(zcglZcdjWarrantIdList);
        }
        total += zcglZcdjWarrantNum;


        if (zcglZcdjAreaNum > 0) {
            List<String> zcglZcdjAreaIdList = zcglZcdjAreaService.list(zcglZcdjAreaQueryWrapper).stream().filter(t -> StringUtil.isNotEmpty(t.getParentId())).map(t -> t.getParentId()).collect(Collectors.toList());
            long count = zcglZcdjAreaService.count();
            if (count > 0) {
                intersectionList.add(zcglZcdjAreaIdList);
            }
            AllIdList.addAll(zcglZcdjAreaIdList);
        }
        total += zcglZcdjAreaNum;


        if (zcglZcdjPhotoNum > 0) {
            List<String> zcglZcdjPhotoIdList = zcglZcdjPhotoService.list(zcglZcdjPhotoQueryWrapper).stream().filter(t -> StringUtil.isNotEmpty(t.getParentId())).map(t -> t.getParentId()).collect(Collectors.toList());
            long count = zcglZcdjPhotoService.count();
            if (count > 0) {
                intersectionList.add(zcglZcdjPhotoIdList);
            }
            AllIdList.addAll(zcglZcdjPhotoIdList);
        }
        total += zcglZcdjPhotoNum;


        List<String> intersection = generaterSwapUtil.getIntersection(intersectionList);
        if (total > 0) {
            if (intersection.size() == 0) {
                intersection.add("jnpfNullList");
            }
            zcglZcdjInfoQueryWrapper.lambda().in(ZcglZcdjInfoEntity::getId, intersection);
        }
        //是否有高级查询
        if (StringUtil.isNotEmpty(superOp)) {
            if (allSuperIDlist.size() == 0) {
                allSuperIDlist.add("jnpfNullList");
            }
            List<String> finalAllSuperIDlist = allSuperIDlist;
            zcglZcdjInfoQueryWrapper.lambda().and(t -> t.in(ZcglZcdjInfoEntity::getId, finalAllSuperIDlist));
        }

        //排序
        if (StringUtil.isEmpty(zcglZcdjInfoPagination.getSidx())) {
            zcglZcdjInfoQueryWrapper.lambda().orderByDesc(ZcglZcdjInfoEntity::getId);
        } else {
            try {
                String sidx = zcglZcdjInfoPagination.getSidx();
                ZcglZcdjInfoEntity zcglZcdjInfoEntity = new ZcglZcdjInfoEntity();
                Field declaredField = zcglZcdjInfoEntity.getClass().getDeclaredField(sidx);
                declaredField.setAccessible(true);
                String value = declaredField.getAnnotation(TableField.class).value();
                zcglZcdjInfoQueryWrapper = "asc".equals(zcglZcdjInfoPagination.getSort().toLowerCase()) ? zcglZcdjInfoQueryWrapper.orderByAsc(value) : zcglZcdjInfoQueryWrapper.orderByDesc(value);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
        if ("0".equals(dataType)) {
            if ((total > 0 && AllIdList.size() > 0) || total == 0) {
                Page<ZcglZcdjInfoEntity> page = new Page<>(zcglZcdjInfoPagination.getCurrentPage(), zcglZcdjInfoPagination.getPageSize());
                IPage<ZcglZcdjInfoEntity> userIPage = this.page(page, zcglZcdjInfoQueryWrapper);
                return zcglZcdjInfoPagination.setData(userIPage.getRecords(), userIPage.getTotal());
            } else {
                List<ZcglZcdjInfoEntity> list = new ArrayList();
                return zcglZcdjInfoPagination.setData(list, list.size());
            }
        } else {
            return this.list(zcglZcdjInfoQueryWrapper);
        }
    }


    @Override
    public ZcglZcdjInfoEntity getInfo(String id) {
        QueryWrapper<ZcglZcdjInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZcglZcdjInfoEntity::getId, id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(ZcglZcdjInfoEntity entity) {
        this.save(entity);
    }

    @Override
    public boolean update(String id, ZcglZcdjInfoEntity entity) {
        return this.updateById(entity);
    }

    @Override
    public void delete(ZcglZcdjInfoEntity entity) {
        if (entity != null) {
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法
    @Override
    public ZcglZcdjAreaEntity getZcglZcdjArea(String id) {
        QueryWrapper<ZcglZcdjAreaEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZcglZcdjAreaEntity::getParentId, id);
        return zcglZcdjAreaService.getOne(queryWrapper);
    }

    @Override
    public ZcglZcdjWarrantEntity getZcglZcdjWarrant(String id) {
        QueryWrapper<ZcglZcdjWarrantEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZcglZcdjWarrantEntity::getParentId, id);
        return zcglZcdjWarrantService.getOne(queryWrapper);
    }

    @Override
    public ZcglZcdjPhotoEntity getZcglZcdjPhoto(String id) {
        QueryWrapper<ZcglZcdjPhotoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ZcglZcdjPhotoEntity::getParentId, id);
        return zcglZcdjPhotoService.getOne(queryWrapper);
    }


    //验证表单唯一字段
    @Override
    public boolean checkForm(ZcglZcdjInfoForm form, int i) {
        int total = 0;
        boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0");
        String id = "";
        if (isUp) {
            id = form.getId();
        }
        if (ObjectUtil.isNotEmpty(form.getZcgl_zcdj_area())) {
        }
        if (ObjectUtil.isNotEmpty(form.getZcgl_zcdj_warrant())) {
        }
        if (ObjectUtil.isNotEmpty(form.getZcgl_zcdj_photo())) {
        }
        if (total > 0) {
            return true;
        }
        return false;
    }

    @Override
    public void operateAction(String id) {
        ZcglZcdjInfoEntity zcglZcdjInfoEntity = this.getById(id);
        zcglZcdjInfoEntity.setStatus(20);
        this.updateById(zcglZcdjInfoEntity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void zcdjInfoChange(ZcglZcdjInfoChangeEntity zcglZcdjInfoChangeEntity) throws DataException {

        ZcglZcdjInfoChangeEntity entity = zcglZcdjInfoChangeMapper.selectById(zcglZcdjInfoChangeEntity.getId());

        //变更json
        String newData = entity.getNewData();
        //原json
        String oldData = entity.getOldData();
        //资产id
        String zcdgId = entity.getZcdgId();
        if (ZcglZcdjInfoChangeEntity.TYPE_1.equals(entity.getType())) {
            ZcglZcdjInfoEntity zcglZcdjInfoEntity = JSONUtil.toBean(newData, ZcglZcdjInfoEntity.class);
            zcglZcdjInfoEntity.setId(zcdgId);
            this.updateById(zcglZcdjInfoEntity);
        }

        if (ZcglZcdjInfoChangeEntity.TYPE_2.equals(entity.getType())) {
            //根据资产id获取权证信息
            ZcglZcdjWarrantEntity zcglZcdjWarrantEntity = zcglZcdjWarrantMapper.selectOne(new QueryWrapper<ZcglZcdjWarrantEntity>()
                    .eq("F_PARENTID", zcdgId)
            );

            JSONObject jsonObject = JSONObject.parseObject(newData);
            ZcglZcdjWarrantEntity zcglZcdjWarrantEntityNew = JSONUtil.toBean(jsonObject.get("zcgl_zcdj_warrant").toString(), ZcglZcdjWarrantEntity.class);
            zcglZcdjWarrantEntityNew.setId(zcglZcdjWarrantEntity.getId());
            System.out.println("是否执行到此处" + zcglZcdjWarrantEntityNew);
            zcglZcdjWarrantMapper.updateById(zcglZcdjWarrantEntityNew);
        }

        if (ZcglZcdjInfoChangeEntity.TYPE_3.equals(entity.getType())) {
            //根据资产id获取登记面积信息
            ZcglZcdjAreaEntity zcglZcdjAreaEntity = zcglZcdjAreaMapper.selectOne(new QueryWrapper<ZcglZcdjAreaEntity>()
                    .eq("F_PARENTID", zcdgId)
            );
            JSONObject jsonObject = JSONObject.parseObject(newData);
            ZcglZcdjAreaEntity zcglZcdjAreaEntityNew = JSONUtil.toBean(jsonObject.get("zcgl_zcdj_area").toString(), ZcglZcdjAreaEntity.class);

//            ZcglZcdjAreaEntity zcglZcdjAreaEntityNew = JSONUtil.toBean(newData, ZcglZcdjAreaEntity.class);
            zcglZcdjAreaEntityNew.setId(zcglZcdjAreaEntity.getId());
            System.out.println("是否执行到此处" + zcglZcdjAreaEntityNew);
            zcglZcdjAreaMapper.updateById(zcglZcdjAreaEntityNew);
        }

        if (ZcglZcdjInfoChangeEntity.TYPE_4.equals(entity.getType())) {
            //根据资产id获取资产近照信息
            ZcglZcdjPhotoEntity zcglZcdjPhotoEntity = zcglZcdjPhotoMapper.selectOne(new QueryWrapper<ZcglZcdjPhotoEntity>()
                    .eq("F_PARENTID", zcdgId)
            );
            ZcglZcdjPhotoEntity zcglZcdjPhotoEntityNew = JSONUtil.toBean(newData, ZcglZcdjPhotoEntity.class);
            zcglZcdjPhotoEntityNew.setId(zcglZcdjPhotoEntity.getId());
            zcglZcdjPhotoMapper.updateById(zcglZcdjPhotoEntityNew);
        }

        if (ZcglZcdjInfoChangeEntity.TYPE_5.equals(entity.getType())) {

            Date date = new Date();
            String userid = userProvider.get().getId();
            //拆分的新资产对象
            List<ZcglZcdjInfoForm> newZcglZcdjInfoForms = JsonUtil.getJsonToList(newData, ZcglZcdjInfoForm.class);
            if (IterUtil.isNotEmpty(newZcglZcdjInfoForms)) {
                for (ZcglZcdjInfoForm newZcglZcdjInfoForm : newZcglZcdjInfoForms) {
                    //新增资产基础信息
                    ZcglZcdjInfoEntity zcglZcdjInfoEntity = new ZcglZcdjInfoEntity();
                    BeanUtil.copyProperties(newZcglZcdjInfoForm, zcglZcdjInfoEntity);
                    String mainId = RandomUtil.uuId();
                    zcglZcdjInfoEntity.setId(mainId);
                    zcglZcdjInfoEntity.setParentId(entity.getId());
                    zcglZcdjInfoEntity.setCreatortime(date);
                    zcglZcdjInfoEntity.setCreatoruserid(userid);
                    zcglZcdjInfoEntity.setStatus(20);
                    baseMapper.insert(zcglZcdjInfoEntity);

                    //新增权证信息
                    ZcglZcdjWarrantModel zcgl_zcdj_warrant = newZcglZcdjInfoForm.getZcgl_zcdj_warrant();
                    ZcglZcdjWarrantEntity zcglZcdjWarrantEntity = new ZcglZcdjWarrantEntity();
                    BeanUtil.copyProperties(zcgl_zcdj_warrant, zcglZcdjWarrantEntity);
                    zcglZcdjWarrantEntity.setParentId(mainId);
                    zcglZcdjWarrantEntity.setCreatortime(date);
                    zcglZcdjWarrantEntity.setCreatoruserid(userid);
                    zcglZcdjWarrantMapper.insert(zcglZcdjWarrantEntity);

                    /*
                     *   新增登记面积信息逻辑(此逻辑取消)
                     *    1.根据原json的面积信息判断每个面积值是否还够拆分
                     *    2.新增完成之后更新之前面积数据
                     * */

                    ZcglZcdjAreaModel new_zcgl_zcdj_area = newZcglZcdjInfoForm.getZcgl_zcdj_area();

//                    ZcglZcdjAreaEntity oldZcglZcdjAreaEntity = zcglZcdjAreaMapper.selectOne(new QueryWrapper<ZcglZcdjAreaEntity>()
//                            .eq("F_PARENTID", entity.getZcdgId())
//                    );
//                    oldZcglZcdjAreaEntity = this.compareArea(new_zcgl_zcdj_area, oldZcglZcdjAreaEntity);

                    ZcglZcdjAreaEntity zcglZcdjAreaEntity = new ZcglZcdjAreaEntity();
                    BeanUtil.copyProperties(new_zcgl_zcdj_area, zcglZcdjAreaEntity);
                    zcglZcdjAreaEntity.setParentId(mainId);
                    zcglZcdjAreaEntity.setCreatortime(date);
                    zcglZcdjAreaEntity.setCreatoruserid(userid);
                    zcglZcdjAreaMapper.insert(zcglZcdjAreaEntity);

                    //更新之前面积信息
//                    oldZcglZcdjAreaEntity.setParentId(zcdgId);
//                    zcglZcdjAreaMapper.update(oldZcglZcdjAreaEntity,new QueryWrapper<ZcglZcdjAreaEntity>()
//                            .eq("F_PARENTID", zcdgId)
//                    );

                    //新增资产近照
                    ZcglZcdjPhotoModel zcgl_zcdj_photo = newZcglZcdjInfoForm.getZcgl_zcdj_photo();
                    ZcglZcdjPhotoEntity zcglZcdjPhotoEntity = new ZcglZcdjPhotoEntity();
                    BeanUtil.copyProperties(zcgl_zcdj_photo, zcglZcdjPhotoEntity);
                    zcglZcdjPhotoEntity.setParentId(mainId);
                    zcglZcdjPhotoEntity.setCreatortime(date);
                    zcglZcdjPhotoEntity.setCreatoruserid(userid);
                    zcglZcdjPhotoMapper.insert(zcglZcdjPhotoEntity);
                }

                //拆分完之后将之前的资产信息删除
                baseMapper.deleteById(zcdgId);
                zcglZcdjWarrantMapper.delete(new QueryWrapper<ZcglZcdjWarrantEntity>()
                        .eq("F_PARENTID", zcdgId)
                );
                zcglZcdjAreaMapper.delete(new QueryWrapper<ZcglZcdjAreaEntity>()
                        .eq("F_PARENTID", zcdgId)
                );
                zcglZcdjPhotoMapper.delete(new QueryWrapper<ZcglZcdjPhotoEntity>()
                        .eq("F_PARENTID", zcdgId)
                );

            }
        }

        if (ZcglZcdjInfoChangeEntity.TYPE_6.equals(entity.getType())) {
            Date date = new Date();
            String userid = userProvider.get().getId();

            //合并的新资产对象
            ZcglZcdjInfoForm newZcglZcdjInfoForm = JSONUtil.toBean(newData, ZcglZcdjInfoForm.class);

            //新增资产基础信息
            ZcglZcdjInfoEntity zcglZcdjInfoEntity = new ZcglZcdjInfoEntity();
            BeanUtil.copyProperties(newZcglZcdjInfoForm, zcglZcdjInfoEntity);
            String mainId = RandomUtil.uuId();
            zcglZcdjInfoEntity.setId(mainId);
            zcglZcdjInfoEntity.setParentId(newZcglZcdjInfoForm.getHbIds());
            zcglZcdjInfoEntity.setCreatortime(date);
            zcglZcdjInfoEntity.setCreatoruserid(userid);
            zcglZcdjInfoEntity.setStatus(20);
            baseMapper.insert(zcglZcdjInfoEntity);

            //新增权证信息
            ZcglZcdjWarrantModel zcgl_zcdj_warrant = newZcglZcdjInfoForm.getZcgl_zcdj_warrant();
            ZcglZcdjWarrantEntity zcglZcdjWarrantEntity = new ZcglZcdjWarrantEntity();
            BeanUtil.copyProperties(zcgl_zcdj_warrant, zcglZcdjWarrantEntity);
            zcglZcdjWarrantEntity.setParentId(mainId);
            zcglZcdjWarrantEntity.setCreatortime(date);
            zcglZcdjWarrantEntity.setCreatoruserid(userid);
            zcglZcdjWarrantMapper.insert(zcglZcdjWarrantEntity);

            /*
             *   新增登记面积信息逻辑
             *    1.将合并的面积进行累加
             * */
            ZcglZcdjAreaModel new_zcgl_zcdj_area = newZcglZcdjInfoForm.getZcgl_zcdj_area();
            ZcglZcdjAreaEntity zcglZcdjAreaEntity = new ZcglZcdjAreaEntity();
            BeanUtil.copyProperties(new_zcgl_zcdj_area, zcglZcdjAreaEntity);
            zcglZcdjAreaEntity.setParentId(mainId);
            zcglZcdjAreaEntity.setCreatortime(date);
            zcglZcdjAreaEntity.setCreatoruserid(userid);
            zcglZcdjAreaMapper.insert(zcglZcdjAreaEntity);

            //新增资产近照
            ZcglZcdjPhotoModel zcgl_zcdj_photo = newZcglZcdjInfoForm.getZcgl_zcdj_photo();
            ZcglZcdjPhotoEntity zcglZcdjPhotoEntity = new ZcglZcdjPhotoEntity();
            BeanUtil.copyProperties(zcgl_zcdj_photo, zcglZcdjPhotoEntity);
            zcglZcdjPhotoEntity.setParentId(mainId);
            zcglZcdjPhotoEntity.setCreatortime(date);
            zcglZcdjPhotoEntity.setCreatoruserid(userid);
            zcglZcdjPhotoMapper.insert(zcglZcdjPhotoEntity);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void zcdjInfoChangeSplit(List<ZcglZcdjInfoChangeEntity> entitys) {


    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ActionResult<?> importExcel(MultipartFile file) throws Exception {
        ImportParams params = new ImportParams();
        params.setHeadRows(1);  // 设置表头的行数（默认是1，表头在文件的第一行）
        params.setSheetNum(1);  // 设置需要导入的工作表（默认是第一个工作表）
        params.setTitleRows(1); // 设置表格标题的行数，如果有的话
        List<ZcglZcdjInfoInfoPoiDTO> dataList = ExcelImportUtil.importExcel(file.getInputStream(), ZcglZcdjInfoInfoPoiDTO.class, params);
        UserInfo userInfo = userProvider.get();
        dataList.stream().forEach(i->{
            ZcglZcdjInfoEntity zcglZcdjInfoEntity = BeanUtil.copyProperties(i, ZcglZcdjInfoEntity.class);
            zcglZcdjInfoEntity.setStatus(10);
            zcglZcdjInfoEntity.setCreatoruserid(userInfo.getUserId());
            zcglZcdjInfoEntity.setCreatortime(new Date());
            zcglZcdjInfoEntity.setAssetClass(this.getDictionaryDataId(zcglZcdjInfoEntity.getAssetClass(),"610000000000000001"));
            zcglZcdjInfoEntity.setZcType(this.getDictionaryDataId(zcglZcdjInfoEntity.getZcType(),"610823865056100147"));
            zcglZcdjInfoEntity.setZcStatus(this.getDictionaryDataId(zcglZcdjInfoEntity.getZcStatus(),"610000000000000000"));
            zcglZcdjInfoEntity.setZcPurpose(this.getDictionaryDataId(zcglZcdjInfoEntity.getZcPurpose(),"610823865056100677"));
            zcglZcdjInfoEntity.setZcSource(this.getDictionaryDataId(zcglZcdjInfoEntity.getZcSource(),"610823965094445381"));
            zcglZcdjInfoEntity.setHoldingMethod(this.getDictionaryDataId(zcglZcdjInfoEntity.getHoldingMethod(),"610823865056100678"));
            zcglZcdjInfoEntity.setZcFmImage("[]");
            zcglZcdjInfoEntity.setZcFile("[]");
            zcglZcdjInfoEntity.setAcquisitionDate(cn.hutool.core.date.DateUtil.parse(i.getAcquisitionDate()));
            //根据导入地址获取经度纬度
            double[] coordinates = new double[2];
            try {
                coordinates = GeoCoder.getCoordinates(i.getAddress(), "fc48e1e74dfb98fbde22eaca6abcbf2d");
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(coordinates.length>0){
                zcglZcdjInfoEntity.setLongitude(String.valueOf(coordinates[0]));
                zcglZcdjInfoEntity.setLatitude(String.valueOf(coordinates[1]));
            }
            this.save(zcglZcdjInfoEntity);

            ZcglZcdjWarrantEntity zcglZcdjWarrantEntity = new ZcglZcdjWarrantEntity(i);
            zcglZcdjWarrantEntity.setCreatoruserid(userInfo.getUserId());
            zcglZcdjWarrantEntity.setCreatortime(new Date());
            zcglZcdjWarrantEntity.setWarrantType(this.getDictionaryDataId(zcglZcdjWarrantEntity.getWarrantType(),"610823865056100177"));
            zcglZcdjWarrantEntity.setPropertyRight(this.getDictionaryDataId(zcglZcdjWarrantEntity.getPropertyRight(),"610826202277478725"));
//            zcglZcdjWarrantEntity.setWarrantStyle(this.getDictionaryDataId(zcglZcdjWarrantEntity.getWarrantStyle(),""));
            zcglZcdjWarrantEntity.setWarrantStyle(this.getDictionaryDataId(zcglZcdjWarrantEntity.getWarrantType(),"677405994166280325"));
            zcglZcdjWarrantEntity.setUseNature(this.getDictionaryDataId(zcglZcdjWarrantEntity.getUseNature(),"610826295164535109"));
            zcglZcdjWarrantEntity.setParentId(zcglZcdjInfoEntity.getId());
            zcglZcdjWarrantEntity.setProductionImage("[]");
            zcglZcdjWarrantEntity.setProductionFile("[]");

            zcglZcdjWarrantMapper.insert(zcglZcdjWarrantEntity);

            ZcglZcdjAreaEntity zcglZcdjAreaEntity = new ZcglZcdjAreaEntity(i);
            zcglZcdjAreaEntity.setCreatoruserid(userInfo.getUserId());
            zcglZcdjAreaEntity.setCreatortime(new Date());
            zcglZcdjAreaEntity.setParentId(zcglZcdjInfoEntity.getId());
            zcglZcdjAreaMapper.insert(zcglZcdjAreaEntity);
        });
        return ActionResult.success("导入成功");
    }

    private String getDictionaryDataId(String name,String id) {
        if(StrUtil.isEmpty(name)){
            return "";
        }
        DictionaryDataEntity dictionaryDataEntity = dictionaryDataMapper.selectOne(new QueryWrapper<DictionaryDataEntity>()
                .eq("F_FULLNAME", name)
                .eq("F_DICTIONARYTYPEID",id)
        );

        if(ObjectUtil.isEmpty(dictionaryDataEntity)){
            return "";
        }

        return dictionaryDataEntity.getEnCode();
    }

    private String getDictionaryDataName(String encode,String id) {

        if(StrUtil.isEmpty(encode)){
            return "";
        }

        DictionaryDataEntity dictionaryDataEntity = dictionaryDataMapper.selectOne(new QueryWrapper<DictionaryDataEntity>()
                .eq("F_ENCODE", encode)
                .eq("F_DICTIONARYTYPEID",id)
        );

        if(ObjectUtil.isEmpty(dictionaryDataEntity)){
            return "";
        }
        return dictionaryDataEntity.getFullName();
    }

    @Override
    public void exportExcel(ZcglZcdjInfoPagination zcglZcdjInfoPagination, HttpServletResponse response) throws IOException {
        // 设置导出的数据
        List<ZcglZcdjInfoEntity> list = this.getList(zcglZcdjInfoPagination);
        List<ZcglZcdjInfoInfoPoiDTO> dataList = new ArrayList<>();
        for (ZcglZcdjInfoEntity ls: list) {
            ZcglZcdjInfoInfoPoiDTO dto = BeanUtil.copyProperties(ls, ZcglZcdjInfoInfoPoiDTO.class);
            //时间转换

            if(ls.getAcquisitionDate()!=null){

                dto.setAcquisitionDate(DateUtil.daFormat(ls.getAcquisitionDate()));

            }

            ZcglZcdjWarrantEntity zcglZcdjWarrantEntity = zcglZcdjWarrantMapper.selectOne(new QueryWrapper<ZcglZcdjWarrantEntity>()
                    .eq("F_PARENTID", dto.getId())
            );
            ZcglZcdjAreaEntity zcglZcdjAreaEntity = zcglZcdjAreaMapper.selectOne(new QueryWrapper<ZcglZcdjAreaEntity>()
                    .eq("F_PARENTID", dto.getId())
            );
            dataList.add(this.setWarrantAndArea(dto,zcglZcdjWarrantEntity,zcglZcdjAreaEntity));
        }

        // 创建Excel文档
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("资产登记导出", "信息表"), ZcglZcdjInfoInfoPoiDTO.class, dataList);

        // 设置响应头
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=zcdj_info.xlsx");
        response.setCharacterEncoding("UTF-8");

        // 输出Excel到浏览器
        workbook.write(response.getOutputStream());
        workbook.close();
    }

    /**
     * 导出数据整体封装
     * @param dto
     * @param zcglZcdjWarrantEntity
     * @param zcglZcdjAreaEntity
     */
    private ZcglZcdjInfoInfoPoiDTO setWarrantAndArea(ZcglZcdjInfoInfoPoiDTO dto, ZcglZcdjWarrantEntity zcglZcdjWarrantEntity, ZcglZcdjAreaEntity zcglZcdjAreaEntity) {

        dto.setAssetClass(this.getDictionaryDataName(dto.getAssetClass(),"610000000000000001"));
        dto.setZcType(this.getDictionaryDataName(dto.getZcType(),"610823865056100147"));
        dto.setZcStatus(this.getDictionaryDataName(dto.getZcStatus(),"610000000000000000"));
        dto.setZcPurpose(this.getDictionaryDataName(dto.getZcPurpose(),"610823865056100677"));
        dto.setZcSource(this.getDictionaryDataName(dto.getZcSource(),"610823965094445381"));
        dto.setHoldingMethod(this.getDictionaryDataName(dto.getHoldingMethod(),"610823865056100678"));

        if(ObjectUtil.isNotEmpty(zcglZcdjWarrantEntity)){
            dto.setUseNature(this.getDictionaryDataName(zcglZcdjWarrantEntity.getUseNature(),"610826295164535109"));
            dto.setPropertyRight(this.getDictionaryDataName(zcglZcdjWarrantEntity.getPropertyRight(),"610826202277478725"));
            dto.setWarrantType(this.getDictionaryDataName(zcglZcdjWarrantEntity.getWarrantType(),"610823865056100177"));
            dto.setCustodyLocation(zcglZcdjWarrantEntity.getCustodyLocation());
            dto.setWarrantNumber(zcglZcdjWarrantEntity.getWarrantNumber());
            dto.setPropertyRightDescribe(zcglZcdjWarrantEntity.getPropertyRightDescribe());
            dto.setWarrantStyleDescribe(zcglZcdjWarrantEntity.getWarrantStyleDescribe());
            if(zcglZcdjWarrantEntity.getIssuanceTime()!=null){
                dto.setIssuanceTime(DateUtil.daFormat(zcglZcdjWarrantEntity.getIssuanceTime()));
            }
            if(zcglZcdjWarrantEntity.getEndTime()!=null){
                dto.setEndTime(DateUtil.daFormat(zcglZcdjWarrantEntity.getEndTime()));
            }
            if(zcglZcdjWarrantEntity.getStartTime()!=null){
                dto.setStartTime(DateUtil.daFormat(zcglZcdjWarrantEntity.getStartTime()));
            }

        }

        if(ObjectUtil.isNotEmpty(zcglZcdjAreaEntity)){
            dto.setBuildingArea(zcglZcdjAreaEntity.getBuildingArea());
            dto.setLandArea(zcglZcdjAreaEntity.getLandArea());
            dto.setSharedLandArea(zcglZcdjAreaEntity.getSharedLandArea());
            dto.setBuildingMeasurementArea(zcglZcdjAreaEntity.getBuildingMeasurementArea());
            dto.setExclusiveArea(zcglZcdjAreaEntity.getExclusiveArea());
            dto.setSharedArea(zcglZcdjAreaEntity.getSharedArea());
        }
        return dto;
    }


    /**
     * 拆分时用于比较面积大小来判定是否还能拆分
     *
     * @param newam
     * @param oldam
     */
    private ZcglZcdjAreaEntity compareArea(ZcglZcdjAreaModel newam, ZcglZcdjAreaEntity oldam) throws DataException {


        if (newam.getBuildingArea().compareTo(oldam.getBuildingArea()) > 0) {
            throw new DataException("证载建筑面积大小不满足拆分");
        } else {
            oldam.setBuildingArea(oldam.getBuildingArea().subtract(newam.getBuildingArea()));
        }

        if (newam.getLandArea().compareTo(oldam.getLandArea()) > 0) {
            throw new DataException("证载土地面积大小不满足拆分");
        } else {
            oldam.setLandArea(oldam.getLandArea().subtract(newam.getLandArea()));
        }

        if (newam.getSharedLandArea().compareTo(oldam.getSharedLandArea()) > 0) {
            throw new DataException("证载共有土地面积大小不满足拆分");
        } else {
            oldam.setSharedLandArea(oldam.getSharedLandArea().subtract(newam.getSharedLandArea()));
        }

        if (newam.getBuildingMeasurementArea().compareTo(oldam.getBuildingMeasurementArea()) > 0) {
            throw new DataException("建筑测量面积大小不满足拆分");
        } else {
            oldam.setBuildingMeasurementArea(oldam.getBuildingMeasurementArea().subtract(newam.getBuildingMeasurementArea()));
        }

        if (newam.getLandSurveyArea().compareTo(oldam.getLandSurveyArea()) > 0) {
            throw new DataException("土地测量面积大小不满足拆分");
        } else {
            oldam.setLandSurveyArea(oldam.getLandSurveyArea().subtract(newam.getLandSurveyArea()));
        }

        if (newam.getExclusiveArea().compareTo(oldam.getExclusiveArea()) > 0) {
            throw new DataException("独用面积大小不满足拆分");
        } else {
            oldam.setExclusiveArea(oldam.getExclusiveArea().subtract(newam.getExclusiveArea()));
        }

        if (newam.getSharedArea().compareTo(oldam.getSharedArea()) > 0) {
            throw new DataException("分摊面积大小不满足拆分");
        } else {
            oldam.setSharedArea(oldam.getSharedArea().subtract(newam.getSharedArea()));
        }

        return oldam;

    }

}
